﻿#region 命名空间

using System;
using System.Web.UI.WebControls;
using WinnerCMS.BLL;
using WinnerCMS.Common;
using WinnerCMS.Model.Attribute;
using WinnerCMS.WebFactory;

#endregion

namespace WinnerCMS.WebUI.Admin.Shop
{
    [Access("MergeOrders")]
    public partial class OrdersMerge : PageBase
    {
        private byte ModelId;
        private readonly OrdersManage MyBLL = new OrdersManage();

        protected void Page_Load(object sender, EventArgs e)
        {
            this.ModelId = byte.Parse(Request.QueryString["ModelId"]);
            if (!IsPostBack)
            {
                this.lblPath.Text = string.Format("{0} → <a href='Order.aspx?ModelId={1}'>订单管理</a> → 订单合并",
                    ModelManage.GetModelName(this.ModelId), this.ModelId);
                BindList();
            }
        }

        #region 绑定数据

        /// <summary>
        ///     绑定数据
        /// </summary>
        private void BindList()
        {
        }

        #endregion

        protected void btnSearchMember_Click(object sender, EventArgs e)
        {
            this.ddlMember.DataSource = new MemberManage().SearchMember(this.txtKey.Text.Trim());
            this.ddlMember.DataTextField = "Name";
            this.ddlMember.DataValueField = "Name";
            this.ddlMember.DataBind();
            this.ddlMember.Items.Insert(0, new ListItem("<请选择>", "0"));
        }

        protected void ddlMember_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.MyBLL.GetOrdersWithUserName(this.ddlOrdersZ, this.ddlMember.SelectedValue);
            this.MyBLL.GetOrdersWithUserName(this.ddlOrdersC, this.ddlMember.SelectedValue);
        }

        protected void btnOK_Click(object sender, EventArgs e)
        {
            this.MyBLL.OrdersMerge(int.Parse(this.ddlOrdersZ.SelectedValue), int.Parse(this.ddlOrdersC.SelectedValue));

            this.txtKey.Text = "";
            this.ddlMember.Items.Clear();
            this.ddlOrdersZ.Items.Clear();
            this.ddlOrdersC.Items.Clear();

            MsgBox.Message("合并完毕！", this.UpdatePanel1);
        }
    }
}